/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uloha4.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import uloha4.entities.ComponentList;
import uloha4.view.MagicCanvas;
import uloha4.view.View;

/**
 *
 * @author Tomique
 */
public class AppController implements ActionListener {

    private MagicCanvas canvas;
    private ComponentList components;
    private View view;

    public AppController(View view) {
        this.view = view;
        this.canvas = MagicCanvas.getInstance();
        this.components = ComponentList.getInstance();
        
    }

    @Override
    public void actionPerformed(ActionEvent e) {

        try {
            JCheckBox check = (JCheckBox) e.getSource();
            switch (check.getText()) {
                case "Antialiasing":
                    canvas.setAntialiasFlag(check.isSelected());
                    break;
                case "Named nodes":
                    canvas.setNodenameFlag(check.isSelected());
                    break;
                case "Force orientation":
                    canvas.setForceOrientFlag(check.isSelected());
                    break;
                case "Visualize lonely nodes":
                    canvas.setVisualizeLonelyNodeFlag(check.isSelected());
                    break;
                case "Visualize node degree":
                    canvas.setVisualizeNodeDegree(check.isSelected());
                    break;
            }


        } catch (ClassCastException ex) {
        }

        try {
            JButton button = (JButton) e.getSource();
            switch (button.getText()) {
                case "All":
                    components.select(true);
                    view.updateTable();
                    break;
                case "None":
                    components.select(false);
                    view.updateTable();
                    break;
                case "Inverse":
                    components.selectInverse();
                    view.updateTable();
                    break;
            }

        } catch (ClassCastException ex) {
        }
        canvas.repaint();
    }
}
